﻿using DevExpress.Mvvm;
using DevExpress.Mvvm.DataAnnotations;
using DXApplication_TestDemo.Models.BindingModels;
using System;

namespace DXApplication_TestDemo.ViewModels
{
    [POCOViewModel()]
    public class MainViewModel : ViewModelBase
    {
        public MainModel MainModels { get; set; }

        public DelegateCommand SelectDataCommand { get; private set; }

        public MainViewModel()
        {
            MainModels = new MainModel();
            MainModels.Age = 111;
            MainModels.Age2 = 222;
            SelectDataCommand = new DelegateCommand(SelectData);

            //注册接收消息
            Messenger.Default.Register<string>(this, "Token1", Token1ReceiveData);
            Messenger.Default.Register<int>(this, "TokenInt", TokenIntReceiveData);

        }

        private void TokenIntReceiveData(int obj)
        {
            MainModels.Age2 = obj;
        }

        private void Token1ReceiveData(string str)
        {
            MainModels.Age2 = int.Parse(str);
        }

        private void SelectData()
        {
            MainModels.Age += 11;
            MainModels.Age2 *= 2;
        }
    }
}
